/*
 Copyright (C) 2013 Yuyao Liang

 This source code is release under the BSD License.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
 

 */
package com.googlecode.stereoplot;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.geom.Arc2D;
import java.awt.geom.Rectangle2D;

import org.jfree.chart.plot.dial.AbstractDialLayer;
import org.jfree.chart.plot.dial.DialLayerChangeEvent;
import org.jfree.chart.plot.dial.DialPlot;

/**
 * @author lianyuy
 * 
 */
public class StereoGridLayer extends AbstractDialLayer{

	private static final double ThirtyDegreeRadius = 0.3d;
	private static final double SixtyDegreeRadius = 0.6d;
	public static final double NintyDegreeRadius = 0.9d;

	/**
	 * The paint used to draw the range highlight. This field is transient
	 * because it requires special handling for serialization.
	 */
	protected transient Paint paint;

	public StereoGridLayer() {
	}

	/**
	 * Returns the paint used to highlight the range.
	 * 
	 * @return The paint (never null).
	 * 
	 * @see #setPaint(Paint)
	 */
	public Paint getPaint() {
		return this.paint;
	}

	/**
	 * Sets the paint used to highlight the range and sends a
	 * {@link DialLayerChangeEvent} to all registered listeners.
	 * 
	 * @param paint
	 *            the paint (null not permitted).
	 * 
	 * @see #getPaint()
	 */
	public void setPaint(Paint paint) {
		if (paint == null) {
			throw new IllegalArgumentException("Null 'paint' argument.");
		}
		this.paint = paint;
		notifyListeners(new DialLayerChangeEvent(this));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jfree.chart.plot.dial.DialLayer#isClippedToWindow()
	 */
	@Override
	public boolean isClippedToWindow() {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jfree.chart.plot.dial.DialLayer#draw(java.awt.Graphics2D,
	 * org.jfree.chart.plot.dial.DialPlot, java.awt.geom.Rectangle2D,
	 * java.awt.geom.Rectangle2D)
	 */
	@Override
	public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
			Rectangle2D view) {
		Rectangle2D thirtyDegreeRectInner = DialPlot.rectangleByRadius(frame,
				StereoGridLayer.ThirtyDegreeRadius,
				StereoGridLayer.ThirtyDegreeRadius);
		Rectangle2D sixtyDegreeRectInner = DialPlot.rectangleByRadius(frame,
				StereoGridLayer.SixtyDegreeRadius,
				StereoGridLayer.SixtyDegreeRadius);
		Rectangle2D nintyDegreeRectInner = DialPlot.rectangleByRadius(frame,
				StereoGridLayer.NintyDegreeRadius,
				StereoGridLayer.NintyDegreeRadius);

		Arc2D arcThirtyDegree = new Arc2D.Double(thirtyDegreeRectInner, 0, 360,
				Arc2D.OPEN);
		Arc2D arcSixtyDegree = new Arc2D.Double(sixtyDegreeRectInner, 0, 360,
				Arc2D.OPEN);
		Arc2D arcNintyyDegree = new Arc2D.Double(nintyDegreeRectInner, 0, 360,
				Arc2D.OPEN);

		g2.setPaint(this.paint);
		g2.setStroke(new BasicStroke(1.0f));
		g2.draw(arcThirtyDegree);
		g2.draw(arcSixtyDegree);
		g2.draw(arcNintyyDegree);
	}

}
